package kandl.automation.reporting.testrail.model;

import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.annotate.JsonValue;

@JsonIgnoreProperties(ignoreUnknown = true)
public class TestRailTestResult {

    @JsonProperty("status_id")
    private TestRailStatus status;

    @JsonProperty("comment")
    private String comment;

    @JsonProperty("id")
    private String id;

    @JsonCreator
    public TestRailTestResult(@JsonProperty("id") String id,
                              @JsonProperty("status_id") TestRailStatus status,
                              @JsonProperty("comment") String comment) {
        this.id = id;
        this.status = status;
        this.comment = comment;
    }

    public TestRailTestResult(TestRailStatus status, String comment) {
        this("0000", status, comment);
    }

    public TestRailTestResult(TestRailStatus success) {
        this(success, "");
    }

    public TestRailTestResult(String id, TestRailTestResult other) {
        this(id, other.getStatus(), other.getComment());
    }

    public TestRailStatus getStatus() {
        return status;
    }

    public String getComment() {
        return comment;
    }

    public String getId() {
        return id;
    }
    
    @JsonProperty("id")
    public int getIdAsInt() {
        return Integer.parseInt(id);
    } 

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        TestRailTestResult that = (TestRailTestResult) o;

        if (comment != null ? !comment.equals(that.comment) : that.comment != null) return false;
        if (id != null ? !id.equals(that.id) : that.id != null) return false;
        if (status != that.status) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = status != null ? status.hashCode() : 0;
        result = 31 * result + (comment != null ? comment.hashCode() : 0);
        result = 31 * result + (id != null ? id.hashCode() : 0);
        return result;
    }
}
